import request from '@/utils/request'

// ==================== 实时报警监控 ====================

// 获取实时报警列表
export function getRealtimeAlarms() {
  return request({
    url: '/operation/api/alarm/realtime/list',
    method: 'get'
  })
}

// 获取未读报警数量
export function getUnreadAlarmCount(userId) {
  return request({
    url: '/operation/api/alarm/unread/count',
    method: 'get',
    params: { userId }
  })
}

// ==================== 报警处理工作台 ====================

// 获取待处理报警列表
export function getPendingAlarms(handlerId) {
  return request({
    url: '/operation/api/alarm/pending/list',
    method: 'get',
    params: { handlerId }
  })
}

// 处理报警
export function handleAlarm(data) {
  return request({
    url: '/operation/api/alarm/handle',
    method: 'post',
    data
  })
}

// 审核报警处理
export function reviewAlarm(data) {
  return request({
    url: '/operation/api/alarm/review',
    method: 'post',
    data
  })
}

// ==================== 历史报警查询 ====================

// 分页查询历史报警
export function queryHistoryAlarms(data) {
  return request({
    url: '/operation/api/alarm/history/query',
    method: 'post',
    data
  })
}

// 获取报警详情
export function getAlarmDetail(id) {
  return request({
    url: `/operation/api/alarm/detail/${id}`,
    method: 'get'
  })
}

// 导出报警数据
export function exportAlarmData(data) {
  return request({
    url: '/operation/api/alarm/export',
    method: 'post',
    data,
    responseType: 'blob'
  })
}

// 导出实时报警数据
export function exportRealtimeAlarmData(data) {
  return request({
    url: '/operation/api/alarm/realtime/export',
    method: 'post',
    data,
    responseType: 'blob'
  })
}

// 导出报警分析报表
export function exportAlarmAnalysisReport(data) {
  return request({
    url: '/operation/api/alarm/analysis/export',
    method: 'post',
    data,
    responseType: 'blob'
  })
}

// ==================== 预警分析报表 ====================

// 获取报警类型统计
export function getAlarmTypeStats(timeDimension, startDate, endDate) {
  return request({
    url: '/operation/api/alarm/analysis/type-stats',
    method: 'get',
    params: { timeDimension, startDate, endDate }
  })
}

// 获取高频报警点统计
export function getHighFreqPoints(limit = 5) {
  return request({
    url: '/operation/api/alarm/analysis/high-freq-points',
    method: 'get',
    params: { limit }
  })
}

// 获取报警趋势数据
export function getAlarmTrend(timeDimension, startDate, endDate) {
  return request({
    url: '/operation/api/alarm/analysis/trend',
    method: 'get',
    params: { timeDimension, startDate, endDate }
  })
}

// 获取处理状态占比
export function getHandleStatusDistribution(startDate, endDate) {
  return request({
    url: '/operation/api/alarm/analysis/status-distribution',
    method: 'get',
    params: { startDate, endDate }
  })
}

// 获取处理效率数据
export function getHandleEfficiency(startDate, endDate) {
  return request({
    url: '/operation/api/alarm/analysis/efficiency',
    method: 'get',
    params: { startDate, endDate }
  })
}

// ==================== 报警来源管理 ====================

// 获取所有报警来源
export function getAllSources() {
  return request({
    url: '/operation/api/alarm/source/list',
    method: 'get'
  })
}

// 根据类型获取报警来源
export function getSourcesByType(sourceType) {
  return request({
    url: '/operation/api/alarm/source/list-by-type',
    method: 'get',
    params: { sourceType }
  })
}

// ==================== 推送管理 ====================

// 手动推送报警
export function pushAlarm(data) {
  return request({
    url: '/operation/api/alarm/push',
    method: 'post',
    data
  })
}

// 更新推送读取状态
export function updatePushReadStatus(data) {
  return request({
    url: '/operation/api/alarm/push/read',
    method: 'post',
    data
  })
}

